﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SocialVoting.Models;
using System.Web.Security;
using Core.Logic.Implementations;

namespace SocialVoting.Controllers
{
    public class AdminController : Controller
    {
        //
        // GET: /Admin/

        public ActionResult Index()
        {
            return View();
        }

        [Authorize(Roles =" Admin")]
        public ActionResult AdminPage()
        {              
            var logic = new UserLogicProvider(new Core.Relations.DataProviderFactory().GetUserDataProvider());
            ViewBag.Users = logic.GetAll();
            return View();
        }

        public ActionResult DeleteUser(Core.Model.User user)
        {
            Membership.DeleteUser(user.UserName);
            var logic = new UserLogicProvider(new Core.Relations.DataProviderFactory().GetUserDataProvider());
            logic.Delete(user.Id);            
            return RedirectToAction("AdminPage");
        }
    }
}
